
/*
 * .
 * All Rights Reserved.
 */
package com.model.demo.designmodel.singleton;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ContainerSingleton
 *
 * @author Liao Dongshan, 2019年05月13日
 *
 */
public class ContainerSingleton {

    private ContainerSingleton(){};

    private static Map<String,Object> ioc=new ConcurrentHashMap<>();

    public static Object getBean(String name){
            synchronized (ioc){
                if (!ioc.containsKey(name)) {
                    Object obj=null;
                    try {
                        Class clazz = Class.forName(name);
                        obj = clazz.newInstance();
                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                    ioc.put(name,obj);
                    return obj;
                }
            }
        return ioc.get(name);

    }

}
